﻿
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Android.Views;

namespace HighFantasy
{
    /// <summary>
    /// Provides extension methods for the TouchCollection type.
    /// </summary>
    public static class TouchCollectionExtensions
    {
        /// <summary>
        /// Determines if there are any touches on the screen.
        /// </summary>
        /// <param name="touchState">The current TouchCollection.</param>
        /// <returns>True if there are any touches in the Pressed or Moved state, false otherwise</returns>
        public static bool TouchPressed(this TouchCollection touchState)
        {
            foreach (TouchLocation location in touchState)
            {
                if (location.State == TouchLocationState.Pressed || location.State ==  TouchLocationState.Moved)
                {
                    return true;
                }
            }
            return false;
        }

        public static bool TouchPressedLocation(this TouchCollection touchState, Rectangle area)
        {
            
        

            foreach (TouchLocation location in touchState)
            {

                int x = (int)location.Position.X;
                int y = (int)location.Position.Y;
                Point pos = new Point(x, y);
                if (location.State == TouchLocationState.Pressed || location.State == TouchLocationState.Moved)
                {

                    if (area.Contains(pos))
                        {
                    return true;
                        }
                }
            }
            return false;
        }

        public static bool TouchMoved(this TouchCollection touchState, GestureType gesture)
        {
            foreach (TouchLocation location in touchState)
            {
                if (location.State == TouchLocationState.Moved && gesture == GestureType.HorizontalDrag)
                {
                    return true;
                }
            }
            return false;
        }

        public static bool TouchDrag(this TouchCollection touchState, GestureType gesture)
        {
            foreach (TouchLocation location in touchState)
            {
                if (location.State == TouchLocationState.Moved && gesture == GestureType.VerticalDrag)
                {
                    return true;
                }
            }
            return false;
        }
    }
}
